import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class query_board {
    public static void main (String[] args) throws IOException{
        if (args.length<1) throw new RuntimeException ("not enough arguments");
        if (args.length>1) throw new RuntimeException ("too many arguments");
        BufferedReader reader = new BufferedReader (new FileReader (new File (args[0])));
        String line;
        int [][] board = new int[256][256]; //initialize
        for (int i = 0;i<256;i++) { //fill in
            for (int j = 0;j<256;j++){
                board[i][j] = 0;
            }
        }
        while ((line = reader.readLine()) != null){
            
            String[] cmd = line.split("\\s");
            if (cmd[0].equals("SetRow")) board = setRow (Integer.parseInt(cmd[1]),Integer.parseInt(cmd[2]),board);
            else if (cmd[0].equals("SetCol")) board = setCol (Integer.parseInt(cmd[1]),Integer.parseInt(cmd[2]),board);
            else if (cmd[0].equals("QueryRow")) System.out.println(queryRow (Integer.parseInt(cmd[1]),board));
            else if (cmd[0].equals("QueryCol")) System.out.println(queryCol (Integer.parseInt(cmd[1]),board));
            else System.err.print("unknown command");
        }
    }
    public static int[][] setRow (int i, int x, int[][]board) {
        for (int j = 0;j<256;j++){
            board[j][i+1] = x;
        }
        return board;
    }
    public static int[][] setCol (int i, int x, int[][]board) {
        for (int j = 0;j<256;j++){
            board[i+1][j] = x;
        }
        return board;
    }
    public static int queryRow (int i, int[][]board){
        int sum = 0;
        for (int j = 0;j<256;j++){
            sum += board[j][i+1];
        }
        return sum;
    }
    public static int queryCol (int i, int[][]board){
        int sum = 0;
        for (int j = 0;j<256;j++){
            sum += board[i+1][j];
        }
        return sum;
    }
}